package com.zg.ktcomwan.vm

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingSource
import androidx.paging.cachedIn

/***
 * @Author:      zxd
 * @CreateDate:  2021/8/16 11:00
 * @Description:
 */
open abstract class AbsViewModel<T : Any> : ViewModel() {

    abstract fun getPagingSource(): PagingSource<Int, T>

    var articleList =
        Pager(
            config = PagingConfig(
                pageSize = 20,
                enablePlaceholders = false,
                initialLoadSize = 20
            ),
            pagingSourceFactory = {
                getPagingSource()
            }
        ).flow.cachedIn(viewModelScope)/*.asLiveData(EmptyCoroutineContext, 1000)*/
    //加上asLiveData就需要使用 netViewModel.articleList.observe() 来获取数据
}